#ifndef __HDVB_EXECQ_H
#define __HDVB_EXECQ_H
/*
    libhdvbd - Library for building sophisticated DVB applications
    Copyright (C) 2012 Tony Houghton <h@realh.co.uk>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/* Allows multiple threads to add requests for function calls to a queue; these
 * functions are then called in order by another thread. It smain purpose is to
 * allow the main thread to throw data at databases without having to wait for
 * SQL statements to execute or being blocked by complex queries.
 */

#include <glib.h>

G_BEGIN_DECLS

typedef void (*HdvbExecQCallback)(gpointer dat1, gpointer dat2, gpointer dat3);

typedef struct _HdvbExecQ HdvbExecQ;

HdvbExecQ *
hdvb_exec_q_new(void);

/* Calls callback(dat1, dat2, dat3) from the queue's thread when it gets to its
 * turn. If block is TRUE, this function waits until the call has been
 * completed. Callback takes 3 data arguments because main use is to add
 * stuff from data2 and data3 to database data1.
 * NB A NULL callback is used internally by hdvb_exec_q_delete to signal the
 * thread to quit.
 */
void
hdvb_exec_q_add_call(HdvbExecQ *q, HdvbExecQCallback callback,
        gpointer data1, gpointer data2, gpointer dat3, gboolean block);

/* Waits until all pending callbacks have been processed */
void
hdvb_exec_q_delete(HdvbExecQ *q);

G_END_DECLS

#endif /* __HDVB_EXECQ_H */
